package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.LpsOrderXcpService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.LpsOrderXcpForm;
import com.youlai.boot.system.model.query.LpsOrderXcpQuery;
import com.youlai.boot.system.model.vo.LpsOrderXcpVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 新产品前端控制层
 *
 * @author lwb
 * @since 2025-07-14 16:24
 */
@Tag(name = "新产品接口")
@RestController
@RequestMapping("/api/v1/lpsOrderXcps")
@RequiredArgsConstructor
public class LpsOrderXcpController  {

    private final LpsOrderXcpService lpsOrderXcpService;

    @Operation(summary = "新产品分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXcp:query')")
    public PageResult<LpsOrderXcpVO> getLpsOrderXcpPage(LpsOrderXcpQuery queryParams ) {
        IPage<LpsOrderXcpVO> result = lpsOrderXcpService.getLpsOrderXcpPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增新产品")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXcp:add')")
    public Result<Void> saveLpsOrderXcp(@RequestBody @Valid LpsOrderXcpForm formData ) {
        boolean result = lpsOrderXcpService.saveLpsOrderXcp(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取新产品表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXcp:edit')")
    public Result<LpsOrderXcpForm> getLpsOrderXcpForm(
        @Parameter(description = "新产品ID") @PathVariable Long id
    ) {
        LpsOrderXcpForm formData = lpsOrderXcpService.getLpsOrderXcpFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改新产品")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXcp:edit')")
    public Result<Void> updateLpsOrderXcp(
            @Parameter(description = "新产品ID") @PathVariable Long id,
            @RequestBody @Validated LpsOrderXcpForm formData
    ) {
        boolean result = lpsOrderXcpService.updateLpsOrderXcp(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除新产品")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderXcp:delete')")
    public Result<Void> deleteLpsOrderXcps(
        @Parameter(description = "新产品ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = lpsOrderXcpService.deleteLpsOrderXcps(ids);
        return Result.judge(result);
    }
}
